﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblAlbumImagesDAO
    {
        private DBService _db = null;
        public TblAlbumImagesDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable InsUpdTblAlbumImages(TblAlbumImages Albums, int mode)
        {
            DataTable dt = null;
            try
            {
                 dt= _db.ExeSP_DataTable("sp_TblAlbumImages_InsUp",
                    new string[] { "@AlbumName", "@DateCreate", "@IDAcc", "@Display","@Mode" },
                    new object[] {  Albums.AlbumName, Albums.DateCreate, Albums.IDAcc, Albums.Display, mode},
                    CommandType.StoredProcedure);

                //flag = true;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetAlbums()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_GetAlbum", false, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetAlbumsByIDAcc( int IDAcc)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_GetAlbumByIDAcc",
                    new string[] { "IDAcc" },
                    new object[] { IDAcc },
                    CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable CheckNumberAlbum(string IDAcc)
        {
       
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblCheckType",
                    new string[] { "@IDAcc" },
                    new object[] { IDAcc }, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public TblAlbumImages GetAll()
        {
            TblAlbumImages albumImage = new TblAlbumImages();

            try
            {
                DataTable dt = _db.ExeSP_DataTable("select * from TblAlbumImages", false, CommandType.Text);
               
                foreach (DataRow dr in dt.Rows)
                {
                    albumImage.AlbumName = dr["AlbumName"].ToString();
                    albumImage.DateCreate = Convert.ToDateTime(dr["DateCreate"].ToString());
                    albumImage.IDAcc = Convert.ToInt32(dr["IDAcc"].ToString());
                    albumImage.Display = Convert.ToBoolean(dr["Display"]);
                    albumImage.IDAlbum = Convert.ToInt32(dr["IDAlbum"].ToString());

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return albumImage;
        }

        public DataTable GetAlbumsById( int IDAlbum)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblAlbumImages where IDAlbum = @IDAlbum",
                    new string[] { "@IDAlbum" },
                    new object[] { IDAlbum },
                 CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable Check5ImageInAlbum(int IDAcc, int IDAlbum)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_Check5ImageInAlbum",
                    new string[] {"IDAcc", "@IDAlbum" },
                    new object[] { IDAcc, IDAlbum },
                 CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
